{include file="public/nheader" /}
<style type="text/css">
    #lay-tableList {
        height: auto;
    }

    .layui-table-view .layui-table[lay-size=lg] .layui-table-cell {
        height: auto;
    }

    #listsss td,
    #listsss th {
        padding: 5px 10px
    }
</style>

<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="isshow" lay-verify="">
                                <option value="">状态</option>
                                <option value="1" {if !empty(input('get.isshow')) &&
                                    input('get.isshow')==1}selected{/if}>显示</option>
                                <option value="2" {if !empty(input('get.isshow')) &&
                                    input('get.isshow')==2}selected{/if}>隐藏</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="产品名称/商品编码" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                        <!-- // 打开添加页面 -->
                        <!-- <button class="layui-btn icon-btn" lay-maxmin="true" lay-open="" data-title="添加"
                            data-area="60%,80%" data-url="/agent/taocan_edit">添加
                        </button> -->
                        <button class="layui-btn layui-btn-green" data-area="50%,70%" data-title="添加组合"
                            data-url="#adminforms" callback="edits" lay-open="">添加组合</button>
                        <button class="layui-btn icon-btn layui-btn-warm" lay-submit lay-filter="excels2">导出组合
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<script type="text/html" id="columnStatus">
    <input type="checkbox" lay-filter="switchStatus" data-url="/agent/taocan_status?id={{d.id}}&field=isshow" lay-skin="switch"
    {{d.isshow==1?'checked':''}}   lay-text="显示|隐藏"   />
</script>
<script type="text/html" id="adminforms">
    <div class="layui-fluid layui-bg-white">
        <form class="layui-form layui-form-fixed" lay-filter="adminforms">
            <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>品牌</label>
            <div class="layui-input-block">
                {foreach $agent as $agents}
                    <input type="radio" name="agentid" value="{$agents.id|default=''}" title="{$agents.nickname|default=''}">
                {/foreach}
            </div>
            </div>
            <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>套餐名称</label>
            <div class="layui-input-block">
                <input name="titles"  placeholder="请填写套餐名称" type="text" class="layui-input" lay-verify="required" />
            </div>
            </div>
                        <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>类型</label>
            <div class="layui-input-block">
                <input type="radio" name="tabtype" value="2" title="新店一键下单">
                <input type="radio" name="tabtype" value="3" title="包装盒类快速下单">
            </div>
            </div>
            <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>温馨提示</label>
            <div class="layui-input-block">
                <textarea name="descs"  placeholder="温馨提示" type="text" class="layui-textarea" ></textarea>
            </div>
            </div>
            <div class="layui-form-item">
            <label class="layui-form-label">排序(默认0,值越大越靠前)</label>
            <div class="layui-input-block">
                <input name="sorts" value="0"  placeholder="请填写排序值" type="number" class="layui-input" lay-verify="required" />
            </div>
            </div>
        <div class="layui-footer layui-form-item layui-center ">
            <button class="layui-btn" lay-filter="submitPage" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >取消</button>
        </div>
        </form>
    </div>
</script>
<script type="text/html" id="tableBar">
    <a class="layui-table-text" style="color: goldenrod;" data-area="50%,70%" data-title="组合名称"  callback="edits" data-url="#adminforms"  lay-event="edit">编辑名称</a>
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" lay-open data-title="产品清单" data-area="90%,90%" data-url="/agent/taocan_edit?id={{d.id}}" >产品清单</a>
        <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" lay-open data-title="添加产品" data-area="90%,90%" data-url="/agent/product?taocanid={{d.id}}" >添加产品</a>
        <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" data-url="/agent/taocan_del?id={{d.id}}" lay-event="del">删除</a>
</script>
{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'upload', 'form'], function () {
        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;
        var upload = layui.upload;
        var form = layui.form;
        //执行实例
        form.on('submit(excels2)', function (data) {
            var checkStatus = table.checkStatus('lay-tableList');
            var checkedData = checkStatus.data;
            var ids = [];
            checkedData.forEach(function (row) {
                ids.push(row.id);
            });
            if (ids.length <= 0) {
                layer.msg('请选择数据', { icon: 2, time: 1000 });
                return;
            }
            var str = ids.join(',');
            window.open('/agent/taocan_excel?ids=' + str, '_blank');
        });
        admin.callback.copyedits = function (clickthis, colletction, config) {
            var tableThis = colletction.tableThis;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {

                // 获取用户id
                var pageThat = layui.$(this);
                pageThat.attr("disabled", true);
                // 开始POST提交数据
                var datas = (tableThis && tableThis.data) || {};
                post.field.id = datas.id || 0;
                layui.$.post("{:url('agent/taocan_copy')}", post.field, function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg);
                        // 关闭当前窗口
                        table.reload('lay-tableList');
                        layer.close(colletction.index);
                    }
                    else {
                        layer.error(res.msg);
                    }
                }, 'json');

                return false;
            })
        }
        admin.callback.edits = function (clickthis, colletction, config) {
            var tableThis = colletction.tableThis;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {

                // 获取用户id
                var pageThat = layui.$(this);
                pageThat.attr("disabled", true);
                // 开始POST提交数据
                var datas = (tableThis && tableThis.data) || {};
                post.field.id = datas.id || 0;
                layui.$.post("{:url('agent/taocan_add')}", post.field, function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg);
                        // 关闭当前窗口
                        table.reload('lay-tableList');
                        layer.close(colletction.index);
                    }
                    else {
                        layer.error(res.msg);
                    }
                }, 'json');

                return false;
            })
        }
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList",
            where: {
                agentid: "{:input('agentid/d',0)}"
            },
            toolbar: 'false'
            , defaultToolbar: [{
                title: '导出excel' //标题
                , layEvent: 'LAYTABLE_EXPORT' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-export' //图标类名
            }, {
                title: '打印页面' //标题
                , layEvent: 'LAYTABLE_PRINT' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-print' //图标类名
            }, {
                title: '筛选数据' //标题
                , layEvent: 'LAYTABLE_COLS' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-cols' //图标类名
            }]
            , limits: [10, 20, 40, 60, 80, 100, 150, 200, 300, 1000, 10000]
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , even: true
            , cols: [[
                { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                { field: 'titles', align: 'center', width: 300, title: '套餐名称' },
                {
                    align: 'center', width: 500, title: '类型', templet: function (item) {
                        if (item.tabtype == 2) {
                            return '<span style="color:green">新店一键下单</span>';
                        }
                        if (item.tabtype == 3) {
                            return '<span style="color:blue">包装盒类快速下单</span>';
                        }
                        return '<span style="color:red">未知</span>';
                    }
                },
                {
                    align: 'center', width: 500, title: '商品详情', templet: function (item) {
                        // var html = '<table id="listsss" class="layui-table"><thead><tr><th>ID</th><th>名称</th<th>规格</th><th>单位</th><th>单价</th><th>数量</th></tr></thead><tbody>';
                        // if (item.productlist.length > 0) {
                        //     item.productlist.forEach(function (item) {
                        //         html += '<tr><td>' + item.id + '</td>';
                        //         html += '<td>' + item.title + '</td>';
                        //         html += '<td>' + item.guige + '</td>';
                        //         html += '<td>' + item.unit + '</td>';
                        //         html += '<td>' + item.numbers + '</td></tr>';
                        //     });
                        // }
                        // html += '</tbody></table>';
                        return '<span style="color:red">请查看产品清单</span>';
                    }
                },
                { field: 'isshow', align: 'center', width: 120, templet: '#columnStatus', title: '状态' },
                { field: 'created', width: 200, align: 'center', title: '添加时间' },
                { align: 'center', toolbar: '#tableBar', width: 350, title: '操作', templet: '#tableBar' },

            ]]
        });
    })
</script>
</body>